<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: "payment-lakala-contract",
});

import { useCrud, useTable, useUpsert, useSearch } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { useI18n } from "vue-i18n";
import UserSelect from "/$/user/components/user-select.vue";

const { service } = useCool();
const { t } = useI18n();

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: t("选择申请人"),
			prop: "userId",
			component: { vm: UserSelect },
			required: true,
		},
		{
			label: t("请求上送的订单号"),
			prop: "orderNo",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
			required: true,
		},
		{
			label: t("选择电子签约申请受理编号"),
			prop: "ecApplyId",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("签署链接"),
			prop: "signUrl",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("合同签署状态，0待处理，1已签署，2签署失败"),
			prop: "status",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
			required: true,
		},
		{
			label: t("失败原因"),
			prop: "failReason",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("进件信息"),
			prop: "applicationData",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
	],
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ label: t("请求上送的订单号"), prop: "orderNo", minWidth: 120 },
		{ label: t("电子签约申请受理编号"), prop: "ecApplyId", minWidth: 120 },
		{ label: t("签署链接"), prop: "signUrl", minWidth: 120 },
		{
			label: t("合同签署状态，0待处理，1已签署，2签署失败"),
			prop: "status",
			minWidth: 120,
		},
		{ label: t("失败原因"), prop: "failReason", minWidth: 120 },
		{ label: t("进件信息"), prop: "applicationData", minWidth: 120 },
		{ type: "op", buttons: ["edit", "delete"] },
	],
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.payment.lakalaContract,
	},
	(app) => {
		app.refresh();
	},
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
